package com.oj.friend.controller.user;

import cn.hutool.core.util.StrUtil;
import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.LoginUser;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.vo.LoginUserVO;
import com.oj.common.core.utils.JwtUtils;
import com.oj.common.file.service.OssService;
import com.oj.friend.domain.user.dto.UserDTO;
import com.oj.friend.domain.user.dto.UserEditDTO;
import com.oj.friend.domain.user.vo.LoginUserInfo;
import com.oj.friend.service.impl.UserServiceImpl;
import io.jsonwebtoken.Claims;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author bin
 * @Date 2025/5/23
 */

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody UserDTO userDTO) {

        return userService.sendCode(userDTO);
    }

    @PostMapping("/code/login")
    public R<String> codeLogin(@RequestBody UserDTO userDTO) {

        return userService.codeLogin(userDTO.getPhone(), userDTO.getCode());
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {

        return userService.logout(token);
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {

        return userService.info(token);
    }

    @GetMapping("/detail")
    public R<LoginUserInfo> detail() {

        return userService.detail();
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody UserEditDTO userEditDTO) {

        return toR(userService.edit(userEditDTO));
    }

    @PutMapping("/head-image/update")
    public R<Void> updateHeadImage(@RequestBody UserEditDTO userEditDTO) {

        return toR(userService.updateHeadImage(userEditDTO.getHeadImage()));
    }

}
